package org.boun.swe.ARCEONE;

import java.util.ArrayList;
import java.util.List;

import org.boun.swe.ARCEONE.R;
import org.boun.swe.ARCEONE.Adapter.ViolationListItemAdapter;
import org.boun.swe.ARCEONE.Data.ViolationObject;
import org.boun.swe.ARCEONE.Static.Constants;
import org.boun.swe.ARCEONE.Static.PinpointType;
import org.boun.swe.ARCEONE.Utility.AsyncTaskListener;
import org.boun.swe.ARCEONE.Utility.JSONManager;

import com.google.gson.reflect.TypeToken;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ListView;

public class ViolationListActivity extends Activity implements AsyncTaskListener{
	private JSONManager jsonManager;
	private ListView ViolationListListView;
	private String url;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.violation_list);

        Intent intent = getIntent();
        url = intent.getStringExtra(Constants.TEMPORARY_SEARCH_URL);
        ViolationListListView = (ListView)findViewById(R.id.violationListListView);
	    
	    jsonManager = new JSONManager(this);
	    jsonManager.GetJSONDataAsync(url, new TypeToken<List<org.boun.swe.ARCEONE.Data.ViolationObject>>(){}.getType());
    }

	@SuppressWarnings("unchecked")
	@Override
	public void onJSONGetCompleted(Object object) {
		List<ViolationObject> violations = (List<ViolationObject>)object;
		List<ViolationObject> openViolations = new ArrayList<ViolationObject>();
		for (ViolationObject violation : violations)
	    	if("ACIK".equals(violation.Status))
	    		openViolations.add(violation);
	    ViolationListItemAdapter violationListItemAdapter = new ViolationListItemAdapter(openViolations, this, false);
	    ViolationListListView.setAdapter(violationListItemAdapter);
	}

	@Override
	public void onJSONPostCompleted() {}

	@Override
	public void onReverseGeocodingCompleted(String address) {}

	@Override
	public void onTap(int index, PinpointType pinpointType) {}

	@Override
	public void onUploadCompleted(String url) {}
}
